

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>高级话题：元数据修复工具 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="故障排除" href="../troubleshooting/" />
    <link rel="prev" title="处理占满的 Ceph 文件系统" href="../full/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../">Ceph 文件系统</a></li>
      <li class="breadcrumb-item active">高级话题：元数据修复工具</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../_sources/cephfs/disaster-recovery-experts.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 文件系统</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../#cephfs">CephFS 入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id4">管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id5">挂载 CephFS</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id6">CephFS 内幕</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../#id7">故障排除和灾难恢复</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../eviction/"> 驱逐客户端</a></li>
<li class="toctree-l3"><a class="reference internal" href="../scrub/"> 洗刷</a></li>
<li class="toctree-l3"><a class="reference internal" href="../full/"> 文件系统占满的处理</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#"> 元数据修复</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id2">导出日志</a></li>
<li class="toctree-l4"><a class="reference internal" href="#dentry">从日志中恢复 dentry</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">舍弃日志</a></li>
<li class="toctree-l4"><a class="reference internal" href="#mds">擦除 MDS 表</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id4">重置 MDS 运行图</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id5">元数据对象丢失的恢复</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id6">用另一个元数据存储池进行恢复</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/"> 故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../disaster-recovery/"> 灾难恢复</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-journal-tool/"> cephfs-journal-tool</a></li>
<li class="toctree-l3"><a class="reference internal" href="../recover-fs-after-mon-store-loss/"> 监视器存储丢失后恢复文件系统</a></li>
<li class="toctree-l3"><a class="reference internal" href="../#id8">开发者指南</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../#id9">更多细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="disaster-recovery-experts">
<span id="id1"></span><h1>高级话题：元数据修复工具<a class="headerlink" href="#disaster-recovery-experts" title="Permalink to this heading"></a></h1>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>如果你没有 CephFS 内部运行机制的专家级知识，
你使用这些工具之前应该寻求帮助。</p>
<p>这里提到的工具们能修好问题，同样也能造成破坏。</p>
<p>尝试修复前，非常有必要理解清楚文件系统的问题到底是什么。</p>
<p>如果你没有专业的技术支持，可以在 ceph-users 邮件列表或 #ceph IRC 频道咨询。</p>
</div>
<section id="id2">
<h2>导出日志<a class="headerlink" href="#id2" title="Permalink to this heading"></a></h2>
<p>尝试危险的操作前，先备份个日志副本，执行下列命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "# ";
}
</style><span class="prompt1">cephfs-journal-tool<span class="w"> </span>journal<span class="w"> </span><span class="nb">export</span><span class="w"> </span>backup.bin</span>
</pre></div></div></section>
<section id="dentry">
<h2>从日志中恢复 dentry<a class="headerlink" href="#dentry" title="Permalink to this heading"></a></h2>
<p>如果日志损坏、或因其它原因导致 MDS 不能重放它，
可以这样尝试恢复文件元数据，执行下列命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-journal-tool<span class="w"> </span>event<span class="w"> </span>recover_dentries<span class="w"> </span>summary</span>
</pre></div></div><p>此命令默认会操作 rank <code class="docutils literal notranslate"><span class="pre">0</span></code> 的 MDS ，给 <code class="docutils literal notranslate"><span class="pre">cephfs-journal-tool</span></code> 命令加选项 <code class="docutils literal notranslate"><span class="pre">--rank=&lt;n&gt;</span></code> 来操作其它 rank 。</p>
<p>此命令会把日志中所有可恢复的 inode/dentry 写入后端存储，
但是，仅限于这些 inode/dentry 的版本号高于后端存储中已有内容的版本时才行。
日志中丢失或损坏的部分会被跳过。</p>
<p>除了写出 dentry 和 inode 之外，
此命令还会更新状态为 <code class="docutils literal notranslate"><span class="pre">in</span></code> 的每个 MDS rank 的 InoTables ，
为的是把已写入的 inode 标识为正在使用。
在简单的案例中，此操作即可使后端存储回到完全正确的状态。</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>此操作不能保证后端存储的状态达到自我一致，
而且在此之后有必要执行 MDS 在线洗刷。
此命令不会更改日志内容，所以把能恢复的给恢复之后，
应该分别裁截日志。</p>
</div>
</section>
<section id="id3">
<h2>舍弃日志<a class="headerlink" href="#id3" title="Permalink to this heading"></a></h2>
<p>如果日志损坏或因故 MDS 不能重放它，你可以这样裁截它：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-journal-tool<span class="w"> </span><span class="o">[</span>--rank<span class="o">=</span>&lt;fs_name&gt;:<span class="o">{</span>mds-rank<span class="p">|</span>all<span class="o">}]</span><span class="w"> </span>journal<span class="w"> </span>reset<span class="w"> </span>--yes-i-really-really-mean-it</span>
</pre></div></div><p>如果这个文件系统有、或曾经有多个活跃的 MDS ，
可以用 <code class="docutils literal notranslate"><span class="pre">--rank</span></code> 选项指定 rank 。</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>重置日志<em>会</em>导致元数据丢失，除非你已经用其它方法
（如 <code class="docutils literal notranslate"><span class="pre">recover_dentries</span></code> ）提取过了。
此操作很可能会在数据存储池中留下一些孤儿对象，
并导致已写过的索引节点被重分配，以致权限规则被破坏。</p>
</div>
</section>
<section id="mds">
<h2>擦除 MDS 表<a class="headerlink" href="#mds" title="Permalink to this heading"></a></h2>
<p>重置日志后，系统状态可能和 MDS 的几张表（ InoTables 、
SessionMap 、 SnapServer ）的内容变得不一致。</p>
<p>要重置 SessionMap （抹掉所有会话），用命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-table-tool<span class="w"> </span>all<span class="w"> </span>reset<span class="w"> </span>session</span>
</pre></div></div><p>此命令会在状态为 <code class="docutils literal notranslate"><span class="pre">in</span></code> 的所有 MDS rank 的表中执行。
如果只想在指定 rank 中执行，把 <code class="docutils literal notranslate"><span class="pre">all</span></code> 换成对应的 MDS rank 。</p>
<p>在所有表中，会话表是最有可能需要重置的表，但是如果你知道你还需要重置其它表，
那就把 <code class="docutils literal notranslate"><span class="pre">session</span></code> 换成 <code class="docutils literal notranslate"><span class="pre">snap</span></code> 或者 <code class="docutils literal notranslate"><span class="pre">inode</span></code> 。</p>
</section>
<section id="id4">
<h2>重置 MDS 运行图<a class="headerlink" href="#id4" title="Permalink to this heading"></a></h2>
<p>一旦文件系统底层的 RADOS 状态（即元数据存储池的内容）恢复到一定程度，
也许有必要更新 MDS 图以反映元数据存储池的内容。
可以用下面的命令把 MDS 图重置到单个 MDS ：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>fs<span class="w"> </span>reset<span class="w"> </span>&lt;fs<span class="w"> </span>name&gt;<span class="w"> </span>--yes-i-really-mean-it</span>
</pre></div></div><p>运行此命令之后， MDS rank 保存在 RADOS 上的任何不为 <code class="docutils literal notranslate"><span class="pre">0</span></code> 的状态都会被忽略：因此这有可能导致数据丢失。</p>
<p><code class="docutils literal notranslate"><span class="pre">fs</span> <span class="pre">reset</span></code> 命令和 <code class="docutils literal notranslate"><span class="pre">fs</span> <span class="pre">remove</span></code> 命令有个不同点。
<code class="docutils literal notranslate"><span class="pre">fs</span> <span class="pre">reset</span></code> 命令会把 rank <code class="docutils literal notranslate"><span class="pre">0</span></code> 留在 <code class="docutils literal notranslate"><span class="pre">active</span></code> 状态，
这样下一个要认领此 rank 的 MDS 守护进程会继续使用已存在于 RADOS 中的元数据；
<code class="docutils literal notranslate"><span class="pre">fs</span> <span class="pre">remove</span></code> 命令会把 rank <code class="docutils literal notranslate"><span class="pre">0</span></code> 留在 <code class="docutils literal notranslate"><span class="pre">creating</span></code> 状态，
意味着磁盘上的现有根索引节点（ root inodes ）会被覆盖。
执行 <code class="docutils literal notranslate"><span class="pre">fs</span> <span class="pre">remove</span></code> 命令会把现有文件变成孤儿文件。</p>
</section>
<section id="id5">
<h2>元数据对象丢失的恢复<a class="headerlink" href="#id5" title="Permalink to this heading"></a></h2>
<p>取决于丢失或被篡改的是哪种对象，
你得运行几个命令生成这些对象的默认版本。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>    <span class="c1"># 会话表</span>
    <span class="n">cephfs</span><span class="o">-</span><span class="n">table</span><span class="o">-</span><span class="n">tool</span> <span class="mi">0</span> <span class="n">reset</span> <span class="n">session</span>
    <span class="c1"># SnapServer 快照服务器</span>
    <span class="n">cephfs</span><span class="o">-</span><span class="n">table</span><span class="o">-</span><span class="n">tool</span> <span class="mi">0</span> <span class="n">reset</span> <span class="n">snap</span>
    <span class="c1"># InoTable 索引节点表</span>
    <span class="n">cephfs</span><span class="o">-</span><span class="n">table</span><span class="o">-</span><span class="n">tool</span> <span class="mi">0</span> <span class="n">reset</span> <span class="n">inode</span>
    <span class="c1"># Journal 日志</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">journal</span><span class="o">-</span><span class="n">tool</span> <span class="o">--</span><span class="n">rank</span><span class="o">=&lt;</span><span class="n">fs_name</span><span class="o">&gt;</span><span class="p">:</span><span class="mi">0</span> <span class="n">journal</span> <span class="n">reset</span> <span class="o">--</span><span class="n">yes</span><span class="o">-</span><span class="n">i</span><span class="o">-</span><span class="n">really</span><span class="o">-</span><span class="n">really</span><span class="o">-</span><span class="n">mean</span><span class="o">-</span><span class="n">it</span>
    <span class="c1"># 根索引节点（ / 和所有 MDS 目录）</span>
    <span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">init</span>
</pre></div>
</div>
<p>最后，根据数据存储池中的内容重新生成丢失文件和目录的元数据对象。
这是个三阶段过程：</p>
<ol class="arabic simple">
<li><p>扫描<em>所有</em>对象以计算索引节点的尺寸和 mtime 元数据；</p></li>
<li><p>从每个文件的第一个对象扫描出元数据并注入元数据存储池。</p></li>
<li><p>检查 inode 的链接情况并修复发现的错误。</p></li>
</ol>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_extents</span> <span class="p">[</span><span class="o">&lt;</span><span class="n">data</span> <span class="n">pool</span><span class="o">&gt;</span> <span class="p">[</span><span class="o">&lt;</span><span class="n">extra</span> <span class="n">data</span> <span class="n">pool</span><span class="o">&gt;</span> <span class="o">...</span><span class="p">]]</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_inodes</span> <span class="p">[</span><span class="o">&lt;</span><span class="n">data</span> <span class="n">pool</span><span class="o">&gt;</span><span class="p">]</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_links</span>
</pre></div>
</div>
<p>如果数据存储池内的文件很多、或者有很大的文件， <code class="docutils literal notranslate"><span class="pre">scan_extents</span></code> 和
<code class="docutils literal notranslate"><span class="pre">scan_inodes</span></code> 命令可能得花费<em>很长时间</em>。</p>
<p>要加快 <code class="docutils literal notranslate"><span class="pre">scan_extents</span></code> 或 <code class="docutils literal notranslate"><span class="pre">scan_inodes</span></code> 的处理进程，
可以让这个工具多跑几个例程。</p>
<p>确定例程数量、再传递给每个例程一个数字，在 <code class="docutils literal notranslate"><span class="pre">(worker_m</span> <span class="pre">-</span> <span class="pre">1)</span></code> 范围内
（也就是 ‘0 到 worker_m 减 1’）。</p>
<p>下面的实例演示了如何同时运行 4 个例程：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Worker 0</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_extents</span> <span class="o">--</span><span class="n">worker_n</span> <span class="mi">0</span> <span class="o">--</span><span class="n">worker_m</span> <span class="mi">4</span>
<span class="c1"># Worker 1</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_extents</span> <span class="o">--</span><span class="n">worker_n</span> <span class="mi">1</span> <span class="o">--</span><span class="n">worker_m</span> <span class="mi">4</span>
<span class="c1"># Worker 2</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_extents</span> <span class="o">--</span><span class="n">worker_n</span> <span class="mi">2</span> <span class="o">--</span><span class="n">worker_m</span> <span class="mi">4</span>
<span class="c1"># Worker 3</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_extents</span> <span class="o">--</span><span class="n">worker_n</span> <span class="mi">3</span> <span class="o">--</span><span class="n">worker_m</span> <span class="mi">4</span>

<span class="c1"># Worker 0</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_inodes</span> <span class="o">--</span><span class="n">worker_n</span> <span class="mi">0</span> <span class="o">--</span><span class="n">worker_m</span> <span class="mi">4</span>
<span class="c1"># Worker 1</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_inodes</span> <span class="o">--</span><span class="n">worker_n</span> <span class="mi">1</span> <span class="o">--</span><span class="n">worker_m</span> <span class="mi">4</span>
<span class="c1"># Worker 2</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_inodes</span> <span class="o">--</span><span class="n">worker_n</span> <span class="mi">2</span> <span class="o">--</span><span class="n">worker_m</span> <span class="mi">4</span>
<span class="c1"># Worker 3</span>
<span class="n">cephfs</span><span class="o">-</span><span class="n">data</span><span class="o">-</span><span class="n">scan</span> <span class="n">scan_inodes</span> <span class="o">--</span><span class="n">worker_n</span> <span class="mi">3</span> <span class="o">--</span><span class="n">worker_m</span> <span class="mi">4</span>
</pre></div>
</div>
<p><strong>切记！！！</strong>所有运行 <code class="docutils literal notranslate"><span class="pre">scan_extents</span></code> 阶段的例程都结束后才能开始进入 <code class="docutils literal notranslate"><span class="pre">scan_inodes</span></code> 阶段。</p>
<p>元数据恢复完后，你可以清理掉恢复期间产生的辅助数据。
执行下列命令运行清理操作：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-data-scan<span class="w"> </span>cleanup<span class="w"> </span>&lt;data<span class="w"> </span>pool&gt;</span>
</pre></div></div><div class="admonition note">
<p class="admonition-title">Note</p>
<p><code class="docutils literal notranslate"><span class="pre">scan_extents</span></code> 、 <code class="docutils literal notranslate"><span class="pre">scan_inodes</span></code> 和 <code class="docutils literal notranslate"><span class="pre">cleanup</span></code> 命令的数据存储池参数是可选的，通常工具能够自动探测存储池。
不过，你也可以覆盖它。
<code class="docutils literal notranslate"><span class="pre">scan_extents</span></code> 命令需要指定所有数据存储池，
而 <code class="docutils literal notranslate"><span class="pre">scan_inodes</span></code> 和 <code class="docutils literal notranslate"><span class="pre">cleanup</span></code> 命令只需要指定主数据存储池。</p>
</div>
</section>
<section id="id6">
<h2>用另一个元数据存储池进行恢复<a class="headerlink" href="#id6" title="Permalink to this heading"></a></h2>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>这个方法尚未全面地测试过，下手时要格外小心。</p>
</div>
<p>如果一个在用的文件系统损坏了、且无法使用，
可以创建一个新的元数据存储池、
并尝试把此文件系统的元数据重构进这个新存储池，
旧的元数据仍原地保留。这是一种比较安全的恢复方法，
因为不会更改现有的元数据存储池。</p>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p>在此过程中，多个元数据存储池包含着指向同一数据存储池的元数据。
在这种情况下，必须格外小心，
以免更改数据存储池内容。一旦恢复结束，
就应该归档或删除损坏的元数据存储池。</p>
</div>
<ol class="arabic">
<li><p>关闭现有文件系统，以防止数据存储池被更改更多；
卸载所有客户端。客户端们全部卸载后，
用下列命令把这个文件系统标记为已失效：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>fs<span class="w"> </span>fail<span class="w"> </span>&lt;fs_name&gt;</span>
</pre></div></div><div class="admonition note">
<p class="admonition-title">Note</p>
<p><code class="docutils literal notranslate"><span class="pre">&lt;fs_name&gt;</span></code> 在这里和下文都是指最初的、损坏的文件系统。</p>
</div>
</li>
<li><p>创建一个恢复文件系统。
这个恢复文件系统将用于恢复已损坏存储池中的数据。
首先，给这个文件系统部署一个数据存储池，
然后，把新元数据存储池关联到新数据存储池上，
然后，设置这个新元数据存储池的后端是旧数据存储池。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>osd<span class="w"> </span>pool<span class="w"> </span>create<span class="w"> </span>cephfs_recovery_meta</span>
<span class="prompt1">ceph<span class="w"> </span>fs<span class="w"> </span>new<span class="w"> </span>cephfs_recovery<span class="w"> </span>cephfs_recovery_meta<span class="w"> </span>&lt;data_pool&gt;<span class="w"> </span>--recover<span class="w"> </span>--allow-dangerous-metadata-overlay</span>
</pre></div></div><div class="admonition note">
<p class="admonition-title">Note</p>
<p>以后，你可以重命名用于恢复的元数据存储池和文件系统。
<code class="docutils literal notranslate"><span class="pre">--recover</span></code> 标记会阻止所有 MDS 加入新文件系统。</p>
</div>
</li>
<li><p>给这个文件系统创建初始元数据：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-table-tool<span class="w"> </span>cephfs_recovery:0<span class="w"> </span>reset<span class="w"> </span>session</span>
</pre></div></div><div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-table-tool<span class="w"> </span>cephfs_recovery:0<span class="w"> </span>reset<span class="w"> </span>snap</span>
</pre></div></div><div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-table-tool<span class="w"> </span>cephfs_recovery:0<span class="w"> </span>reset<span class="w"> </span>inode</span>
</pre></div></div><div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-journal-tool<span class="w"> </span>--rank<span class="w"> </span>cephfs_recovery:0<span class="w"> </span>journal<span class="w"> </span>reset<span class="w"> </span>--force<span class="w"> </span>--yes-i-really-really-mean-it</span>
</pre></div></div></li>
<li><p>从数据存储池重建元数据存储池，执行下列命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-data-scan<span class="w"> </span>init<span class="w"> </span>--force-init<span class="w"> </span>--filesystem<span class="w"> </span>cephfs_recovery<span class="w"> </span>--alternate-pool<span class="w"> </span>cephfs_recovery_meta</span>
</pre></div></div><div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-data-scan<span class="w"> </span>scan_extents<span class="w"> </span>--alternate-pool<span class="w"> </span>cephfs_recovery_meta<span class="w"> </span>--filesystem<span class="w"> </span>&lt;fs_name&gt;</span>
</pre></div></div><div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-data-scan<span class="w"> </span>scan_inodes<span class="w"> </span>--alternate-pool<span class="w"> </span>cephfs_recovery_meta<span class="w"> </span>--filesystem<span class="w"> </span>&lt;fs_name&gt;<span class="w"> </span>--force-corrupt</span>
</pre></div></div><div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-data-scan<span class="w"> </span>scan_links<span class="w"> </span>--filesystem<span class="w"> </span>cephfs_recovery</span>
</pre></div></div><div class="admonition note">
<p class="admonition-title">Note</p>
<p>上面的每一个扫描都要覆盖整个数据存储池。
需要相当多的时间才能完成。
看看前面的段落，把这个任务分配到多个作业进程上。</p>
</div>
<p>如果损坏的文件系统包含脏日志数据，
随后可以用如下命令恢复：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">cephfs-journal-tool<span class="w"> </span>--rank<span class="o">=</span>&lt;fs_name&gt;:0<span class="w"> </span>event<span class="w"> </span>recover_dentries<span class="w"> </span>list<span class="w"> </span>--alternate-pool<span class="w"> </span>cephfs_recovery_meta</span>
</pre></div></div></li>
<li><p>恢复完之后，有些恢复过来的目录其统计信息不对。
首先确保 <code class="docutils literal notranslate"><span class="pre">mds_verify_scatter</span></code> 和 <code class="docutils literal notranslate"><span class="pre">mds_debug_scatterstat</span></code>
参数的值为 <code class="docutils literal notranslate"><span class="pre">false</span></code> （默认值），
以防 MDS 检查这些统计信息：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>config<span class="w"> </span>rm<span class="w"> </span>mds<span class="w"> </span>mds_verify_scatter</span>
</pre></div></div><div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>config<span class="w"> </span>rm<span class="w"> </span>mds<span class="w"> </span>mds_debug_scatterstat</span>
</pre></div></div><div class="admonition note">
<p class="admonition-title">Note</p>
<p>还需要核对尚未全局设置、
或用本地 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 文件配置的。</p>
</div>
</li>
<li><p>允许 MDS 加入恢复文件系统：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>fs<span class="w"> </span><span class="nb">set</span><span class="w"> </span>cephfs_recovery<span class="w"> </span>joinable<span class="w"> </span><span class="nb">true</span></span>
</pre></div></div></li>
<li><p>运行正向<cite>洗刷 scrub &lt;/cephfs/scrub&gt;</cite> 以修复递归统计信息。确保有一个 MDS 守护进程在运行，然后执行命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>tell<span class="w"> </span>mds.cephfs_recovery:0<span class="w"> </span>scrub<span class="w"> </span>start<span class="w"> </span>/<span class="w"> </span>recursive,repair,force</span>
</pre></div></div><div class="admonition note">
<p class="admonition-title">Note</p>
<p><a class="reference external" href="https://tracker.ceph.com/issues/46166">符号链接恢复</a>
从 Quincy 版开始支持。</p>
<p>符号链接被恢复成了空的普通文件。</p>
</div>
<p>建议尽快迁移已恢复文件系统上的数据。
已恢复的文件系统可以运作后，
不要再恢复旧文件系统。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>如果数据存储池也损坏了，有些文件可能没法恢复，
因为与之相关的回溯信息丢失了。
如果有数据对象丢失了
（由于数据存储池内的归置组丢失之类的问题），
恢复的文件里在丢失数据的位置会有空洞。</p>
</div>
</li>
</ol>
</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../full/" class="btn btn-neutral float-left" title="处理占满的 Ceph 文件系统" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../troubleshooting/" class="btn btn-neutral float-right" title="故障排除" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>